<?php
namespace app\yticnus\Controller;
class ContactUs extends Common {

	/*
	*	构造函数
	*/
	function __construct(){
		parent::__construct();
    }
    
	/*
	*	联系我们列表
	*/
	public function index(){
        if(request()->isPost()){
            $phone = input('phone');
            $QQ = input('QQ');
            $wechat = input('wechat');
            $q_logo = request()->file('q_logo');
            $recharge = input('recharge');
            if(!empty($phone)){
                $data['phone'] = $phone;
            }
            //if(!empty($QQ)){
            //}
                $data['QQ'] = $QQ;
            if(!empty($wechat)){
                $data['wechat'] = $wechat;
            }
            if(!empty($q_logo)){
                $info = $q_logo->move(ROOT_PATH . 'public/static/uploads');
                if($info){
                    $data['q_logo'] = $info->getSaveName();
                }
            }
            if(!empty($recharge)){
                $data['recharge'] = $recharge;
            }
            $res = db('contact_us')->where('id','1')->update($data);
			//$sql = db('contact_us')->getLastSql();
			//$this->success($sql);//UPDATE `ty_contact_us` SET `phone`='12345678912',`wechat`='123456',`recharge`='pay1253.com' WHERE `id` = 1
            if(!$res) $this->error('修改失败');
            $this->success('修改成功');
        }
        $data = db('contact_us')->where('id',1)->find();
        $this->assign('data',$data);
		return $this->fetch();
	}
}